float4 g_colours[4] = {{1,0,0,1},{0,1,0,1},{0,0,1,1},{0.0,0.0,0.0,1}};
float2 g_tc[4] = {{0,0},{0,1},{1,1},{1,0}};

float4x4 View;
float4x4 Projection;

float2 level_ll;
float2 level_dims;

texture Texture;
sampler Sampler = sampler_state
{
    Texture = (Texture);
    
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    
    AddressU = Clamp;
    AddressV = Clamp;
};

struct VertexShaderInput
{
    float4 Position : POSITION0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float2 Texcoord : TEXCOORD0;
    float4 Color : TEXCOORD1;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
    
    float2 wcspos = input.Position.xz;
    float2 projpos = (wcspos - level_ll) / level_dims;
    
    //output.Position = float4(projpos*2.0 - 1.0,0,1);
	
	output.Position = float4(input.Position.x,0.1,input.Position.z,1.0);
	output.Position = mul(output.Position, View);
	output.Position = mul(output.Position, Projection);

    output.Texcoord = g_tc[int(input.Position.w)];
    output.Color = g_colours[int(input.Position.y)];

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    float v = tex2D(Sampler,input.Texcoord).r;
    float4 c = v;
    c.rgb = v*input.Color;
    return c;
}

technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
